#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<vector<int>> divideArray(vector<int>& nums, int k) {
        ranges::sort(nums);
        vector<vector<int>> res;
        for (int i = 0; i < nums.size(); i += 3)
        {
            if (nums[i] + k >= nums[i + 2])
                res.push_back({ nums[i], nums[i + 1], nums[i + 2] });
            else
                return vector<vector<int>>();
        }
        return res;
    }
};